package com.itgaohe.dao.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itgaohe.dao.entity.Blog;
import com.itgaohe.dao.entity.Like;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface BlogMapper extends BaseMapper<Blog> {
    @Select("SELECT * FROM tb_blog " +
            "WHERE cursor_index < #{cursor} " +
            "ORDER BY cursor_index DESC LIMIT 6 ")
    List<Blog> getBlogslist(@Param("cursor") Long cursor);
    @Select("SELECT * FROM tb_blog " +
            "WHERE cursor_index < #{cursor} AND user_id = #{userId} " +
            "ORDER BY cursor_index DESC LIMIT 6 ")
    public List<Blog> getBlogbyUserId(@Param("userId")Long userId,@Param("cursor")Long cursor);


    //查询是否已经点赞
    @Select("SELECT COUNT(*) FROM tb_like WHERE user_id = #{userId} AND blog_id = #{blogId}")
    int existsLike(@Param("userId") Long userId, @Param("blogId") Long blogId);


    //删除喜欢
    @Delete("DELETE FROM tb_like WHERE user_id = #{userId} AND blog_id = #{blogId}")
    int deleteLike(@Param("userId") Long userId, @Param("blogId") Long blogId);

    @Select("SELECT * FROM tb_blog " +
            "WHERE cursor_index < #{cursor} AND user_id = #{userId} " +
            "ORDER BY cursor_index DESC LIMIT 6 ")
    public List<Blog> getBlogbyId(@Param("userId")Long userId,@Param("cursor")Long cursor);


}
